(function(){
	let username = document.querySelector(".phone >input");
	let password = document.querySelector(".check div>input");
	let loginbnt = document.querySelector(".an");
	console.log(username,password,loginbnt)
	const goodsId = json.getUrlData("goodsId");
	//登录请求
	loginbnt.onclick = function(){
		if(username.value == '' || password.value == ''){
			alert('用户名或密码不能为空');
			return;
		};
		
		json.post(URL  + '/api_user',{
			username : username.value.trim(),
			password : password.value.trim(),
			status : 'login'
		}, even =>{
			console.log(even)
			if(even.code != 0){
				console.log(even);
				alert('用户名或密码错误');
				return;
			};
			
			localStorage.setItem('username', even.username);
			localStorage.setItem('token', even.user_id);
			alert("登录成功");
			if(goodsId){
				location.href = `product.html?goodsId=${goodsId}`;
			}else{
				location.href = 'mian.html';
			};
			
		});
	}
	
})();